package fibTests;

public class FibCycle implements IFib {
	private int iterations;
	
	public FibCycle() {
		iterations = 0;
	}
	
	@Override
	public int getLastIterationsCounter() {
		return iterations;
	}

	@Override
	public long fib(int n) {
		if (n <= 0) return 0;
		long current = 1;
		long previous = 1;
		iterations = 0;
		for (int i = 3; i <= n; i++) {
			iterations++;
			long t = current;
			current = current + previous;
			previous = t;
		}
		return current;
	}

}
